<?php
//define('NO_CHECK_LOGIN','ture');
//显示除去 E_NOTICE 之外的所有错误信息---------------
error_reporting( E_ALL || ~E_NOTICE );
date_default_timezone_set("Asia/Shanghai");
//-----------------------------------------------
require 'init.php';
if(isset($_SESSION['cms']['admin'])){
		$user=$_SESSION['cms']['admin'];
	}
if ( @$user[ 'username' ] != '' ) {
    $userid=$user['userid'];
    $login="退出登录";
	$herf="../model/userdata.php?";
	if(file_exists("../../upload/userphoto/userphoto_$userid.jpg")){
          $photo = "../../upload/userphoto/userphoto_$userid.jpg";  
        }else{
          $photo = "../../upload/userphoto/userphoto_0.jpg";
        }
    }else{
    $login="去登录";
	$herf="../view/login.html";                
	$photo = "../../upload/userphoto/userphoto_0.jpg";
    }
$comment_user=mysqli_query($link,"SELECT `username` FROM `usertable` WHERE `userid`='$userid'");
$comment_user=mysqli_fetch_all($comment_user,MYSQLI_ASSOC);
$comment_username=$comment_user[0]['username'];
$comment_text=I('comment_text','post','html','未输入');
//提交后获取用户ip和留言时间-------------------------
$comment_ip = $_SERVER[ "REMOTE_ADDR" ]; //IP地址
$comment_time=date("Y-m-d H:i:s",time()); //添加时间戳  
//插入数据---------------------------------------------------------------
if($_POST){
   mysqli_query($link,"INSERT INTO commenttable(`userid`,`commentusername`,`commenttext`,`commenttime`,`commentip`) VALUES('$userid','$comment_username','$comment_text', '$comment_time','$comment_ip')");
   echo "<script>alert ('留言上传成功，请勿重复提交');</script>";
    redirect('../model/comment.php');     
}
$commentdata=mysqli_query($link,'SELECT * FROM commenttable ORDER BY commentid DESC');
$commentdata = mysqli_fetch_all($commentdata,MYSQLI_ASSOC);
mysql_close();
//----------------------------------------------------------------------

require '../view/comment.html';
?>